//
//  AllKindNextViewController.m
//  DongChiDaChiProject1
//
//  Created by lanou3g on 15/10/31.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "AllKindNextViewController.h"
#import "AllNextTableViewCell.h"
#import "AllDataHandle.h"
#import "AllKindNextDetailViewController.h"

@interface AllKindNextViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation AllKindNextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 建立数据源
    [self addData];
    // 添加tableView
    [self addTableV];
    [self.navigationController.navigationBar setTranslucent:NO];
    [self addBar];
}

#pragma mark - 添加bar
- (void)addBar
{
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(returnToLast:)];
    leftItem.tintColor = [UIColor colorWithHue:0.8 saturation:1 brightness:0.7 alpha:1];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    [self.navigationController.navigationBar setTranslucent:NO];
}

- (void)returnToLast:(UIBarButtonItem *)barItem
{
    [self.navigationController popViewControllerAnimated:YES];
}

// 建立数据源
- (void)addData
{
    [[AllDataHandle shareAllDataHandle] requestDetailAllDataByIndex:self.myID AndReturn:^(NSArray *array) {
        [self.tableView reloadData];
    }];
}

// 添加tableView
- (void)addTableV
{
    self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    //self.tableView.backgroundColor = [UIColor orangeColor];
    UIView *footV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidthFitParameter, 60 * kWidthFitParameter)];
    footV.layer.cornerRadius = 30;
        footV.backgroundColor = [UIColor colorWithHue:0.1 saturation:0.3 brightness:1 alpha:1];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake((kScreenWidth - 200 * kWidthFitParameter) / 2, 5 * kWidthFitParameter, 200 * kWidthFitParameter, 50 * kWidthFitParameter)];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [[UIColor magentaColor] colorWithAlphaComponent:0.7];
   // label.textColor = [UIColor whiteColor];
        label.text = @"懂吃达吃";
        [footV addSubview:label];
    self.tableView.tableFooterView = footV;
    [self.view addSubview:_tableView];
}

#pragma mark - 必须实现的2个方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[AllDataHandle shareAllDataHandle] returnCountOfDetailCell];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"AllNextTableViewCell";
    AllNextTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[AllNextTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    cell.allNextModel = [[AllDataHandle shareAllDataHandle] returnDetailModelByIndexPath:indexPath];
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100 * kWidthFitParameter;
}

#pragma mark - 点击tableview的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 关闭tableView的选中状态
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    AllKindNextDetailViewController *allKindNextDetailVC = [[AllKindNextDetailViewController alloc] init];
    allKindNextDetailVC.allNextModel = [[AllDataHandle shareAllDataHandle] returnDetailModelByIndexPath:indexPath];
    allKindNextDetailVC.fetchArray = [[AllDataHandle shareAllDataHandle] returnStepArrayByIndexPath:indexPath];
    
    [self.navigationController pushViewController:allKindNextDetailVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
